<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html lang="en">
	<head>
	<base href="<%=basePath%>"><!-- jsp文件头和头部 -->
	<%@ include file="../../system/admin/top.jsp"%> 
	</head>
<body>
			<!-- 检索  -->
			<form action="department/list.do" method="post" name="Form" id="Form">
			<!-- 检索  -->
		 <div class="con-form" >
					     <input autocomplete="off" id="nav-search-input" type="text" name="keyWord" value="${pd.keyWord}" placeholder="这里输入关键词" />
					     <button class="search" onclick="search();"  title="查询">查询</button>
					</div>
					<p class="operate">
		                  <a class="create Operate" title="新增"  onclick=" add()">新增</a>
		                  <a class="delete" onclick="makeAll();" title="批量删除">批量删除</a>
		             </p>
					<table>
						    <colgroup>
				            <col width="2%">
				            <col width="2%">
				            <col width="8%">
				            <col width="5%">
				            <col width="6%">
				            <col width="5%">
				        </colgroup>
						<thead>
					<tr>
						<th>
						<input type="checkbox" id="zcheckbox" />
						</th>
						<th class="center">序号</th>
						<th class="center">部门名称</th>
						<th class="center">描述</th>
						<th class="center">创建时间</th>
						<th class="center">操作</th>
					</tr>
				</thead>
				<tbody>
				<!-- 开始循环 -->	
				<c:choose>
					<c:when test="${not empty varList}">
						<c:if test="${QX.cha == 1 }">
						<c:forEach items="${varList}" var="var" varStatus="vs">
							<tr>
								<td>
									<input type='checkbox' name='ids' value="${var.department_id}" />
								</td>
								<td>${vs.index+1}</td>
								<td>${var.department_name}</td>
								<td>${var.department_remark}</td>
								<td>${var.create_date}</td>
								<td>
									<c:if test="${var.department_parent != 0 }">
											  <c:if test="${QX.edit != 1 && QX.del != 1}">
											        <div class="operate-more">
									                        <span class='operate-false'></span>
								                    </div>
											    </c:if>
												<c:if test="${QX.edit == 1}">
												<a class="operatea revise" title="编辑" onclick="edit('${var.department_id}');" >编辑</a>
												</c:if>
												<c:if test="${QX.del == 1}">
												<a class="operatea delete" title="删除" onclick="del('${var.department_id}');" >删除</a>
												</c:if>
									</c:if>
								</td>
							</tr>
						</c:forEach>
						</c:if>
						<c:if test="${QX.cha == 0 }">
							<tr>
								<td colspan="100" class="center">您无权查看</td>
							</tr>
						</c:if>
					</c:when>
					<c:otherwise>
						<tr class="main_info">
							<td colspan="100" class="center" >没有相关数据</td>
						</tr>
					</c:otherwise>
				</c:choose>
				</tbody>
			</table>
				<div class="branchPage">${page.pageStr}</div>
		</form>
		<script type="text/javascript">
		//检索
		function search(){
			$("#Form").submit();
		}
		
		//新增
		function add(){
			$("#zhongxin",domObj).show();
			$("#zhongxin iframe",domObj).attr("src","<%=basePath%>department/goAdd.do");
		}
			//删除
			function del(Id){
				$.confirm('你确定要删除这条消息吗? ',null,function(type){
			        if(type==='yes'){
						var url = "<%=basePath%>department/delete.do?department_id="+Id+"&tm="+new Date().getTime();
						$.get(url,function(data){
								if(data == "success"){
									location.href="<%=basePath%>company/list.do";
								}
						});
			        }else{
			        	//do Nothing
			        }
			        this.hide();
				 });
			}
		//修改
		function edit(Id){
			$("#zhongxin",domObj).show();
			$("#zhongxin iframe",domObj).attr("src","<%=basePath%>department/goEdit.do?department_id="+Id);
		}
		//批量操作
		function makeAll(){
		var str = '';
		for(var i=0;i < document.getElementsByName('ids').length;i++){
			  if(document.getElementsByName('ids')[i].checked){
			  	if(str==''){
			  		str += document.getElementsByName('ids')[i].value;
			  	}else{
			  		str += ',' + document.getElementsByName('ids')[i].value;
			  	}
			  }
		}
		if(str==''){
			$("#zcheckbox").tips({
				side:1,
	            msg:'点这里全选',
	            bg:'#AE81FF',
	            time:8
	        });
			return;
		}
		$.confirm('你确定要删除这条消息吗? ',null,function(type){
	        if(type==='yes'){
	        	$.ajax({
	    			type: "POST",
	    			url: '<%=basePath%>department/deleteAll.do?tm='+new Date().getTime(),
	    	    	data: {DATA_IDS:str},
	    			dataType:'json',
	    			cache: false,
	    			success: function(data){
	    				//刷新列表页面
	    				location.href='<%=basePath%>department/list.do';
	    			}
	    		});
	        }else{
	           //do Nothing
	        }
	        this.hide();
	    });
	}
		</script>
	</body>
</html>

